import pytest
import os

@pytest.fixture(scope="session", autouse=True)
def set_allure_env():
    """设置Allure环境变量"""
    os.environ['ALLURE_RESULTS_DIR'] = os.path.join(
        os.path.dirname(os.path.dirname(__file__)),
        'reports',
        'allure'
    )
import yaml
import os
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 读取配置文件
def load_config():
    with open('config/config.yaml', 'r', encoding='utf-8') as f:
        return yaml.safe_load(f)

@pytest.fixture(scope='session')
def config():
    return load_config()

@pytest.fixture(scope='session')
def env_config(config, request):
    env = request.config.getoption('--env')
    return config['environments'][env]

@pytest.fixture
def api_client(env_config):
    base_url = env_config['base_url']
    timeout = env_config['timeout']
    return {
        'base_url': base_url,
        'timeout': timeout
    }

def pytest_addoption(parser):
    parser.addoption(
        '--env', action='store', default='test',
        help='environment to run tests against: dev, test, prod'
    )

# Allure报告配置
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
    config.option.allure_report_dir = 'reports/allure'
